<?php
/**
 * Created by PhpStorm.
 * User: win7
 * Date: 2018/12/23
 * Time: 17:27
 */
require 'config.php';
switch (@$_GET['a']) {
    case 'exit':
        $time = date('Y-m-d H:i:s');
        $uname = $_COOKIE['uname'];
        $sql ="update user set lastlogin = '{$time}' where userName = '{$uname}'";
        mysqli_query($link,$sql);
        if (mysqli_affected_rows($link)>0){
            setcookie('uname','',time()-1,'/');
            setcookie('auth','',time()-1,'/');
            echo "<script>alert('退出成功');window.location.href='../index.php';</script>";die;
        }
        mysqli_close($link);
        break;
    case 'zhuang':
        if ($_POST['zhuang'] == '开启'){
            $sql = "update config set status = 1";
            mysqli_query($link,$sql);
            if (mysqli_affected_rows($link)>0){
                echo "<script>alert('开启成功');window.location.href='./wang.php';</script>";die;
            }
            mysqli_close($link);
        }else{
            $sql = "update config set status = 0";
            mysqli_query($link,$sql);
            if (mysqli_affected_rows($link)>0){
                echo "<script>alert('关闭成功');window.location.href='./wang.php';</script>";die;
            }
            mysqli_close($link);
        }

        break;
}